package com.lhjmall.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lhjmall.common.utils.PageUtils;
import com.lhjmall.common.utils.R;
import com.lhjmall.product.dto.ProductDto;
import com.lhjmall.product.entity.ProductEntity;
import com.lhjmall.product.service.ProductService;



/**
 *
 *
 * @author longhaijin
 * @email 287245878@qq.com
 * @date 2021-03-10 21:30:10
 */
@RestController
@RequestMapping("product/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     * @throws Exception
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) throws Exception{
		ProductDto product = productService.getByIdForC(id);

        return R.ok().put("product", product);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ProductEntity product){
		productService.save(product);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ProductEntity product){
		productService.updateById(product);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		productService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
